var g_tansLayer = null;
var TransLayer = cc.LayerColor.extend({
    _shareLabel : null,
    ///////////// constructor /////////////
    ctor:function () {
        ///////////// 1. super init first /////////////
        this._super();
        g_tansLayer = this;
        this.setColor( cc.color.BLACK );
        this.opacity = 255;
        // add touch event
        //this.addTouchEvent();
        /////////// get win size //////////////////
        var size = cc.director.getWinSize();

        this.addCanvas();
        this.AddMenu();

        /////////////// setting score label///////////////////////////
        this._shareLabel = cc.LabelTTF.create("下一关", "Arial", 25 );
        this._shareLabel.x = size.width * 0.5;
        this._shareLabel.y = size.height * 0.5;
        this._shareLabel.setColor( cc.color.BLUE );
        this._shareLabel.setScale(1.6);
        this.addChild( this._shareLabel, 10 );

        //this.schedule( this.nextLevel,1.5);
        return true;
    },
    addTouchEvent : function(){
        cc.eventManager.addListener({
            event: cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches: true,
            onTouchBegan: this.onTouchBegan
        }, this );
    },
    ////////////////////////////////////////////////
    onTouchBegan : function (touch, event) {
       this.nextLevel(0);
        return true;
    },

    addCanvas : function(){
        var filename = MainResource("nextC.jpg");
        var background = new cc.Sprite(filename);
        background.setPosition( cc.p(cc.winSize.width/2,cc.winSize.height/2) );
        this.addChild(background);
    },
    AddMenu : function(){
        var filename = MainResource("nextL0.png");
        var filename1 = MainResource("nextL1.png");
        var begin = new cc.MenuItemImage(filename,filename1,this.onBeginMenu , this);
        begin.setPosition( cc.p(cc.winSize.width/2,100) );
        var menu = cc.Menu.create( begin );
        menu.setPosition(cc.p(0,0));
        this.addChild( menu );
    },
    onBeginMenu : function(sender){
        this.nextLevel();
    },
    nextLevel : function(dt){
        TransitionGame();
        g_tansLayer.removeFromParent(true);
    }

});

TransitionGame=function(){
    // clear game
    RemoveMainLayer(true);
    // update game
    AddMainLayer(g_mainScene);
    // resetting ui
    ResettingUiLayer();
    cc.log("next level");
}
